package Operation;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

public class Borrowed implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("借出图书！");
        System.out.println("输入要借书名：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        int ret = bookList.getUsedSize();
        for (int i = 0; i < ret; i++) {
            Book book = bookList.getBook(i);
            if(book.getName().equals(name)){
                if(!book.isBorrowed()){
                    book.setBorrowed(true);
                    System.out.println("借书成功！");
                    return;
                }else {
                    System.out.println("已经借出！");
                    return;
                }
            }
        }
        System.out.println("没有这本书！");
    }
}
